<template>
  <div :style="{ height: height, width: width }" />
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    str: String,
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    showValue: Number,
    showColor: String,
    otherValue: Number,
     lineDataX: Array,
    lineDataY: Array,
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.chart.setOption({
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "shadow",
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            data: this.lineDataX,
            axisTick: {
              alignWithLabel: true,
            },
            axisLabel: {
              interval: 0,
              rotate: 40,
              color: '#000000'
            },
          },
        ],
        yAxis: [
          {
            type: "value",
            axisLabel: {
              color: '#000000'
            },
          },
        ],
        series: [
          {
            name: this.str,
            type: "bar",
            barWidth: "60%",
            itemStyle: {
              color: "rgba(91, 143, 249, 0.85)",
            },
            data: this.lineDataY,
          },
        ],
      });
    },
  },
};
</script>
